<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <div>
        <h3>{{gender}}-{{enGender}}</h3>
        <h3>{{gender}}-{{cnGender}}</h3>
      </div>
    </div>
    <script src="./vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          gender: 2,
        },
        computed: {
          enGender() {
            const g = { 1: "boy", 2: "girl" };
            return g[this.gender]; //g[2]
          },
          cnGender: {
            get() {
              const g = { 1: "男", 2: "女" };
              return g[this.gender];
            },
            set(value) {
              const g = { 男: 1, 女: 2 };
              this.gender = g[value];
            },
          },
        },
        mounted() {
          setTimeout(() => {
            this.cnGender = "男";
          }, 3000);
        },
      });
    </script>
  </body>
</html>
